|
|
|
|
|
|
|
Figure 29.4
Here, you can see the report layout for the
sample project, after adding the header fields. |
|
|
|
|
|
|
|
|
Now that you have determined how you want the report to look, you have to add a few lines of code to display the report. Add a second command button, cmdReport, to the form. Make the caption Display Report. Enter the code from Listing 29.2 in the command button's Click event procedure. |
|
|
|
|
|
|
|
|
Listing 29.2 RPTDEMOShowing the Report to the Users |
|
|
|
|
|
|
|
|
Private Sub cmdReport_Click()
Dim s As String
s = "Prepared by Abe Froman"
Set DataReport1.DataSource = rs
DataReport1.Sections("rptHeader").Controls("lblPerson").Caption = s
DataReport1.Show
End Sub |
|
|
|
|
|
|
|
|
The code in Listing 29.2 sets the DataSource property of the DataReport object to the ADO recordset rs. |
|
|
|
|
|
|
|
|
|
In this example, you use an ADO recordset as the data source. However, you can also use other types of data sources, such as a Data Environment, in which case you can set the DataSource property at designtime.  |
|
|
|
|
|
|
|
|
|
|
Next, the code sets the Caption property of the label control in the report header. Finally, the Show method is invoked, causing the report to be displayed. |
|
|
|
|
|
|
|
|
To test the sample report, run the project and click the Fill Recordset button. After you see the message box stating that the recordset has been filled, click the Display Report button. The Data Report should appear on a separate form in Print Preview mode, as pictured in Figure 29.5. |
|
|
|
|
|